﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game
{
    namespace RenderTechnique
    {
        class ForwardTechnique : PostProcessRenderTechnique
        {

            public ForwardTechnique(TechniqueDescription desc)
                : base(desc)
            {
            }

            public override void Init()
            {
                base.Init();

                InitSunShadow();

                InitOutput();
                // Step 1.0 : gen gbuffer

                IDK.ShaderProgram program = Description.Core.GetShaderProgram("ForwardShading");
                mBaseShader = program;

                // Step 1.1 : add parameter
                program.AddParameter(IDK.ShaderProgram.Parameter.Type.VertexAttribute, IDK.ShaderProgram.Parameter.Declaration.VertexPosition, "position");
                program.AddParameter(IDK.ShaderProgram.Parameter.Type.VertexAttribute, IDK.ShaderProgram.Parameter.Declaration.VertexNormal, "normal");
                program.AddParameter(IDK.ShaderProgram.Parameter.Type.VertexAttribute, IDK.ShaderProgram.Parameter.Declaration.VertexTangent, "tangent");
                program.AddParameter(IDK.ShaderProgram.Parameter.Type.VertexAttribute, IDK.ShaderProgram.Parameter.Declaration.VertexTexCoord, "tcoord");

                program.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.MatrixProjection, "gProj");
                program.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.MatrixView, "gView");
                program.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.MatrixWorld, "gWorld");

                program.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.MatrixViewInverse, "gViewInv");
                program.AddParameterData(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Constant44f, "gShadowMatrix", SunShadowLightMatrix);

                program.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Texture0, "decalMap");
                program.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Texture1, "bumpMap");
                program.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Texture2, "gShadowMap");


                Description.Renderer.AddPass(new IDK.ForwardShadingPass(Description.Core.GetScene(),
                    /*cam*/Description.Camera,
                    RTTShadow, 
                    RTTOutput));

                //Init Postprocess
                InitPostrocess();
            }
        }
    }
}
